from sklearn.cluster import KMeans
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import time
from tqdm import tqdm

dataPath = 'E:/working/微球数据/kmeans-16points_no_optimizer.csv'
data = pd.read_csv(dataPath)
print(data.info)

time.sleep(5)

FSC = list(data['FSC'])
APC = list(data['APC'])


def Kmeans(*n):
    for k in tqdm(n):

        points = []
        for i in range(len(FSC)):
            points.append([FSC[i], APC[i]])

        X = np.array(points)

        estimator = KMeans(n_clusters=k)
        y_pre = estimator.fit(X)
        cen = y_pre.cluster_centers_
        # print(estimator.cluster_centers_)

        plt.scatter(X[:, 0], X[:, 1])
        plt.scatter(cen[:, 0], cen[:, 1], c='red', s=80, marker='o')
        plt.show()
        time.sleep(1)


Kmeans(6, 8, 16)
